#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#include "cyassl/ctaocrypt/aes.h"

unsigned long long get_usec()
{
    struct timeval t;
    gettimeofday(&t, NULL);
    return (((unsigned long long)t.tv_sec) * 1000000) + t.tv_usec;
}

int main(void) {

	unsigned long long start;
	unsigned long long duration;
	//int i;
	//int N = 100;

	unsigned char str[] = "Hello Ruhma Ali";

	printf("Plaintext = %s\n", str);
	//printf("%lu\n", sizeof(str));

	Aes enc;
	Aes dec;

	// 128 bit Key
	const byte key[] = {0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1f};
	// 192 bit Key
	//const byte key[] = {0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1f,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a};
	// 256 bit Key
	//const byte key[] = {0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1f,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1f};

	const byte iv[] = {0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a,0xb4,0xaf,0x98,0x1a};


	byte plain[16];   // an increment of 16, fill with data
	byte cipher[16];

	start = get_usec();

	//for( i = 0; i < N; i++ )
	//{
	// encrypt
	AesSetKey(&enc, key, sizeof(key), iv, AES_ENCRYPTION);
	AesCbcEncrypt(&enc, cipher, str, sizeof(str));

	// decrypt
	AesSetKey(&dec, key, sizeof(key), iv, AES_DECRYPTION);
	AesCbcDecrypt(&dec, plain, cipher, sizeof(cipher));
	//}
	duration = get_usec() - start;

	printf("Time with %lu bit Key: %d micro seconds\n", sizeof(key)*8 , (int) (duration));
	printf("Ciphertext = %s\n", cipher);
	printf("Plaintext = %s\n", plain);

	return EXIT_SUCCESS;
}
